#ifndef _VALIDATORBASE_H_
#define _VALIDATORBASE_H_
#include "Utility.h"
#include "SimpleRefection.h"
#include "MgrBase.h"
class Reactor;
class CombatObj;
class CombatSessionImp;

class ValidatorSkillBase
{
public:
	virtual bool Validate(const Reactor * pRecator) const  =0;
};
typedef std::tr1::shared_ptr<ValidatorSkillBase> TValidatorSkillPtr;

class ValidatorObjBase
{
public:
	virtual bool Validate(CombatObj * pObj) const  =0;
	virtual ~ValidatorObjBase(){}
};
typedef std::tr1::shared_ptr<ValidatorObjBase> TValidatorObjPtr;

class ContextValidatorBase
{
public:
	virtual bool Validate(uint8 iPlayerID,CombatSessionImp * pContext) const  =0;
	virtual ~ContextValidatorBase(){};
};
typedef std::tr1::shared_ptr<ContextValidatorBase> TContextValidatorPtr;

class ValidatorEachBase
{
public:
	virtual bool Validate(CombatObj * pOwner,CombatObj * pTarget) const  =0;
	virtual ~ValidatorEachBase(){}
};
typedef std::tr1::shared_ptr<ValidatorEachBase> TValidatorEachPtr;

class TObjValidators:public ReflectionBase
{
	DECL_REFLECTION(TObjValidators,"../../config/ValidatorObj.xml");
public:
	rewrite virtual void OnArchieveReaded();
	  bool Validate(CombatObj * pObj) const
	  {
		  std::vector<TValidatorObjPtr>::const_iterator it=m_vValidators.begin();
		  for(;it!=m_vValidators.end();++it)
		  {
				if(!(*it)->Validate(pObj)) return false;
		  }
		  return true;
	  }
	  void Add(TValidatorObjPtr pValidator)
	  {
		  m_vValidators.push_back(pValidator);
	  }
	  ~TObjValidators();
	  int32 m_iID;
	  std::string m_sDisplayName;
	  ETriple m_tiAliveOrDead;
	  std::vector<int32> m_vObjInStorages;
	  std::vector<int32> m_vHasSkills;
	  std::vector<int32> m_vNotHasSkills;

	  std::vector<int32> m_vHasSkillInCategorys;
	  

	  std::vector<int32> m_vRaceIn;
	  std::vector<int32> m_vRaceNotIn;
	  int32 m_iFightTurnEqual;
	  std::vector<int32> m_vObjTypeIn;
	  std::vector<int32> m_vObjTypeNotIn;
	  ETriple m_tiHpFullOrNot;
	  
	  ECompare m_eHpCompare;
	  int32 m_iHpAbsValue;
	  float m_fPercentValue;
	
	  int32 m_iEachValidorFacedCard;

private:
	 std::vector<TValidatorObjPtr> m_vValidators;
};
typedef DefMangerTpl<TObjValidators> ValidatorObjManager;

class TSkillValidators:public ReflectionBase
{
	DECL_REFLECTION(TSkillValidators,"../../config/ValidatorSkill.xml");
public:
	rewrite virtual void OnArchieveReaded();
	bool  Validate(const Reactor * pRecator) const
	{
		std::vector<TValidatorSkillPtr>::const_iterator it=m_vValidators.begin();
		for(;it!=m_vValidators.end();++it)
		{
			if(!(*it)->Validate(pRecator)) return false;
		}
		return true;
	}
	void Add(TValidatorSkillPtr pValidator)
	{
		m_vValidators.push_back(pValidator);
	}
	int32 m_iID;
	std::string m_sDisplayName;
	std::vector<int32> m_vTypeIn;
	std::vector<int32> m_vTypeNotIn;
	std::vector<int32> m_vCategoryMustInclude;
	std::vector<int32> m_vCategoryMustNotInclude;
	~TSkillValidators();
private:
	std::vector<TValidatorSkillPtr> m_vValidators;
};
typedef DefMangerTpl<TSkillValidators> ValidatorSkillManager;

class TEachValidators:public ReflectionBase
{
	DECL_REFLECTION(TEachValidators,"../../config/ValidatorEach.xml");
public:
	rewrite virtual void OnArchieveReaded();
	bool  Validate(CombatObj * pOwner,CombatObj * pTarget) const
	{
		std::vector<TValidatorEachPtr>::const_iterator it=m_vValidators.begin();
		for(;it!=m_vValidators.end();++it)
		{
			if(!(*it)->Validate(pOwner,pTarget)) return false;
		}
		return true;
	}
	void Add(TValidatorEachPtr pValidator)
	{
		m_vValidators.push_back(pValidator);
	}
	~TEachValidators();
	int32 m_iID;
	std::string m_sDisplayName;
	ECompare m_eHpCompare;
	ECompare m_eHpMaxCompare;
	ETriple m_tiBeSameRace;
	ETriple m_tiBeSelf;
	ETriple m_tiBeSameSide;
	std::vector<int32> m_vHasBuffOfMine;
	std::vector<int32> m_vNotHasBuffOfMine;

private:
	std::vector<TValidatorEachPtr> m_vValidators;
};
typedef DefMangerTpl<TEachValidators> ValidatorEachManager;

class TContextValidators:public ReflectionBase
{
	DECL_REFLECTION(TContextValidators,"../../config/ValidatorContext.xml");
public:
	rewrite virtual void OnArchieveReaded();
	bool  Validate(uint8 iPlayerID,CombatSessionImp * pContext) const
	{
		std::vector<TContextValidatorPtr>::const_iterator it=m_vValidators.begin();
		for(;it!=m_vValidators.end();++it)
		{
			if(!(*it)->Validate(iPlayerID,pContext)) return false;
		}
		return true;
	}
	void Add(TContextValidatorPtr pValidator)
	{
		m_vValidators.push_back(pValidator);
	}

	int32 m_iID;
	std::string m_sDisplayName;
	uint32 m_iTurnNum;
	ECompare m_eTurnNumCamp;

	ELogicOpt m_eLogicPot;
	ETriple m_tiBeOurSide;
	ECardStorage m_eFieldType;
	std::vector<int32> m_vRaces;
	std::vector<int32> m_vTypes;
	int32 m_iCardNum;
	ECompare m_eCardNumComp;

	ETriple m_tiBeOurSide2;
	ECardStorage m_eFieldType2;
	std::vector<int32> m_vRaces2;
	std::vector<int32> m_vTypes2;
	int32 m_iCardNum2;
	ECompare m_eCardNumComp2;

	ETriple	 m_tiBeOurSideHeroHp;
	double m_fHeroHpPercent;
	ECompare m_eHeroHpComp;

	ETriple	 m_tiBeOurSideHeroSp;
	int32	 m_iHeroSp;
	ECompare m_eHeroSpComp;

	ETriple	 m_tiBeOurSideTombLock;
	bool	 m_bLock;
	~TContextValidators();

private:
	std::vector<TContextValidatorPtr> m_vValidators;
};
typedef DefMangerTpl<TContextValidators> ValidatorContextManager;

// typedef  std::vector<const ValidatorSkillBase*> TSkillValidators;
// typedef  std::vector<const ValidatorObjBase*> TObjValidators;
// typedef  std::vector<const ContextValidatorBase*> TContextValidators;
// typedef  std::vector<const ValidatorEachBase*> TEachValidators;

#endif